<template>
    <div class="chat-message-box">
        <div class="chat-bubble" ref="chatBubble" :style="{ backgroundColor: bubbleBgColor }">
            <p>{{ content }}</p>

        </div>

    </div>
</template>

<script setup>
    import { useLoginUserStore } from '@/store/useLoginUserStore'

    import { defineProps, ref, onMounted, watchEffect } from 'vue'

    const loginUserStore = useLoginUserStore()



    const props = defineProps(['message'])
    const srcUid = ref(0), targetUid = ref(0), content = ref(''), type = ref(''), dir = ref(0)
    const chatBubble = ref(null)
    const bubbleBgColor = ref('white')
    const init = () => {
        srcUid.value = props.message.srcUid || 0
        targetUid.value = props.message.targetUid || 0
        content.value = props.message.content || 'null'
        type.value = props.message.type || ''
        if (srcUid.value === loginUserStore.uid) {
            dir.value = 1
            bubbleBgColor.value = props.message.srcUid === loginUserStore.uid ? 'blue' : 'white'

        }

    }

    watchEffect(() => {
        init()
    })
    onMounted(() => {
        init()

    })

</script>

<style lang="less" scoped>
    * {
        padding: 0;
        margin: 0;
        line-height: 1;
    }

    .chat-message-box {
        // min-height: 44px;
        width: 100%;
        padding: 8px;
        display: flex;

        .chat-bubble {
            max-width: 80%;
            background-color: white;
            padding: 0 10px;
            border-radius: 5px;

            // overflow-x: auto;

            p {
                white-space: normal;
                word-wrap: break-word;
                line-height: 28px;
            }
        }
    }
</style>